<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
        <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" style="text-align:center">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatch">批量处理</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
      :scroll="{ x: 1500 }"
    >
    <template slot="action" slot-scope="text,record">
        <a @click="handleReview(record)">审查</a>
      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  <!-- 审查 -->
  <audit-handle @close="handleReviewClose" @success="handleReviewSuccess" :auditHandleVisible="auditHandleVisible" :info="auditHandleData" ></audit-handle>
    </a-card>
</div>
</template>

<script>
import AuditHandle from './auditHandle'
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    AuditHandle
  },
  data () {
    return {
      auditHandleVisible: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '报名号',
          dataIndex: 'bmh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '报考院系',
          dataIndex: 'bkyx'
        },
        {
          title: '报考专业',
          dataIndex: 'bkzy'
        },
        {
          title: '研究方向',
          dataIndex: 'yjfx'
        },
        {
          title: '外语',
          dataIndex: 'wy'
        },
        {
          title: '业务课一',
          dataIndex: 'ywky'
        },
        {
          title: '业务课二',
          dataIndex: 'ywke'
        },
        {
          title: '加试科目',
          dataIndex: 'jskm'
        },
        {
          title: '总分',
          dataIndex: 'zf'
        },
        {
          title: '报考导师',
          dataIndex: 'bkds'
        },
        {
          title: '状态',
          dataIndex: 'zt'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [] // 院系
      },
      auditHandleData: {}
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          bmh: 'A001',
          xm: '001',
          bkyx: '电子院',
          bkzy: 'what',
          yjfx: '计算机',
          wy: 'AI',
          ywky: '100',
          ywke: '80',
          jskm: '计算机',
          zf: '99',
          bkds: '王老师',
          zt: '正常',
          key: 1
        }, {
          bmh: 'A001',
          xm: '001',
          bkyx: '电子院',
          bkzy: 'what',
          yjfx: '计算机',
          wy: 'AI',
          ywky: '100',
          ywke: '80',
          jskm: '计算机',
          zf: '99',
          bkds: '王老师',
          zt: '正常',
          key: 12
        }, {
          bmh: 'A001',
          xm: '001',
          bkyx: '电子院',
          bkzy: 'what',
          yjfx: '计算机',
          wy: 'AI',
          ywky: '100',
          ywke: '80',
          jskm: '计算机',
          zf: '99',
          bkds: '王老师',
          zt: '不正常',
          key: 17
        }]
      })
    },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      console.log('导出')
    },
    // 审查
    handleReview (data) {
      console.log('审查')
      this.auditHandleData = {
        bmh: 'jd',
        xm: '假的',
        wy: '假的',
        ywy: '假的',
        ywe: '假的',
        shbz: '假的',
        jskm: '假的',
        fskm: '假的',
        zcj: '假的',
        yx: '假的',
        zy: '假的',
        yz: '',
        yj: '',
        bkds: '阿黄'
      }
      this.auditHandleVisible = true
    },
    // 允许
    handleAllow () {
      console.log('允许')
    },
    // 批量处理
    handleBatch () {
      console.log('批量处理')
    },
    // 关闭审查弹层
    handleReviewClose () {
      this.auditHandleVisible = false
    },
    // 保存
    handleReviewSuccess () {
      this.auditHandleVisible = false
      this.$message.success('添加成功')
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
